Page({
  data: {
    // 模拟新增粉丝数据，含“是否已关注”状态
    followers: [
      {
        id: 1,
        avatar: 'https://picsum.photos/100/100?random=3', 
        username: '西瓜', 
        time: '3分钟前',
        isFollowed: false // 初始为“未关注”
      },
      {
        id: 2,
        avatar: 'https://picsum.photos/100/100?random=3',
        username: '西瓜',
        time: '3分钟前',
        isFollowed: false
      },
      {
        id: 3,
        avatar: 'https://picsum.photos/100/100?random=3',
        username: '西瓜',
        time: '3分钟前',
        isFollowed: false
      }
    ]
  },

  // 切换“关注/已关注”状态
  toggleFollow(e) {
    const { index } = e.currentTarget.dataset; // 获取点击的粉丝索引
    const { followers } = this.data;
    const targetFollower = followers[index];

    // 切换关注状态
    targetFollower.isFollowed = !targetFollower.isFollowed;

    // 更新数据
    this.setData({
      followers: [...followers]
    });

    // 弹出提示
    wx.showToast({
      title: targetFollower.isFollowed ? '关注成功' : '取消关注',
      icon: 'none', // 不使用默认图标，避免与文字冲突
      duration: 1500
    });
  },

  // 返回上一页
  navigateBack() {
    wx.navigateBack();
  }
});